package com.demo.framework.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 
* @ClassName: SharedPreferencesUtil 
* @Description: TODO(封装 SharedPreferences) 
* @author 谢云腾
* @date 2013-3-22 上午11:20:27 
* @version 1.0
 */
public class SharedPreferencesUtil {
	public static final String PREFS_NAME = "JITPresFile";

	/**
	 * 获取应用环境参数
	 * 
	 * @param context
	 * @param name
	 *            参数名
	 * @return
	 */
	public static String getSetting(Context context, String name) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		return setting.getString(name, "");
	}

	public static int getSettingInt(Context context, String name) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		return setting.getInt(name, 0);
	}

	public static float getSettingFloat(Context context, String name) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		return setting.getFloat(name, 0.0f);
	}

	public static long getSettingLong(Context context, String name) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		return setting.getLong(name, 0);
	}

	public static boolean getSettingBoolean(Context context, String name) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		return setting.getBoolean(name, false);
	}

	/**
	 * 设置应用程序环境参数
	 * 
	 * @param context
	 * @param name
	 *            参数名
	 * @param value
	 *            值
	 */
	public static void setSetting(Context context, String name, String value) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = setting.edit();
		editor.putString(name, value);
		editor.commit();
	}

	public static void setSetting(Context context, String name, int value) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = setting.edit();
		editor.putInt(name, value);
		editor.commit();
	}

	public static void setSetting(Context context, String name, float value) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = setting.edit();
		editor.putFloat(name, value);
		editor.commit();
	}

	public static void setSetting(Context context, String name, long value) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = setting.edit();
		editor.putLong(name, value);
		editor.commit();
	}

	public static void setSetting(Context context, String name, boolean value) {
		SharedPreferences setting = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = setting.edit();
		editor.putBoolean(name, value);
		editor.commit();
	}
}
